<template>
    <el-row class="ThrowPackage">
        <el-col :span="24" class="ThrowPackageLinePage-box">
            <div id="ThrowPackage" ref="ThrowPackage" class="ThrowPackageLinePage"></div>
        </el-col>
    </el-row>
</template>>

<script>
import { fetchData } from '@/api/index.js';
import bus from 'common/bus.js';


export default {
    data() {
        return {
            postData: {
                opera: 'OSNetworkIfDiscards',
                curPage: 1,
                pageSize: 10,
                sort: {
                    sortColumn: 'alldiscards',
                    sortOrders: 'desc'
                },
                filtersType: 'fuzzyquery',
                filters: {
                    "monid":" "
                },
            },
            ThrowPackage: {},
            CPUx: 0,
            CPUy: 0,
            EChartsOption: {
                animationDuration: 100,
                animationEasingUpdate: 'quinticInOut',
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: ''
                    }
                },
                grid: {
                    top: '4%',
                    left: '3%',
                    right: '4%',
                    height: '90%',
                    containLabel: true
                },
                xAxis: {
                    useData: [],
                    data: [],
                    axisLabel: {
                        show: false
                    },
                    axisTick:{
                        show: false,
                    },
                    axisLine: {color:'rgb(29, 140, 248)',lineStyle:{color:'rgb(29, 140, 248)'}}
                },
                yAxis: {
                    axisLine: {color:'rgb(29, 140, 248)',lineStyle:{color:'rgb(29, 140, 248)'}},
                    type: 'value',
                    min: 0,
                    splitLine: { 
                        lineStyle: {
                            color: 'rgb(29, 140, 248)',
                            opacity: 0.1
                        }
                    }
                },
                series: [{
                    name: '总丢包数：',
                    data: [],
                    type: 'bar',
                    color: 'rgb(0, 121, 200)',
                    barWidth: '50%',
                }]
            },
            timerName: 'ThrowPackage',
            timerEventName: 'timerThrowPackage',
            timerInterval: 1000 * 30
        }
    },
    created() {
        bus.$on('selectedNetMonID', msg => {


            // 获取数据
            this.selectedMonID = msg;
            this.postData.filters.monid = this.selectedMonID.selectedNETMonID;
            this.getData();
        });

        bus.$emit('timerNewTodo', {
            name: this.timerName,
            eventName: this.timerEventName,
            interval: this.timerInterval,
            intervalNow: 0
        });

        bus.$on(this.timerEventName, msg => {
            if (msg.isGetData) {
                this.getData();
            }
        });
    },
    mounted() {
        this.ThrowPackage = this.$echarts.init(this.$refs.ThrowPackage);
        this.initFileSystemLine();
    },
    computed: {
        postDataFn() {
            return {
                postData : JSON.stringify(this.postData)
            }
        }
    },
    methods: {
        getData(){
            fetchData(
                this.postDataFn
            ).then((res) => {
                this.EChartsOption.xAxis.data = [];
                this.EChartsOption.xAxis.useData = [];
                let _arr = res.data.slice(0, 5);
                _arr.forEach(item => {
                    this.EChartsOption.xAxis.data.push((item.IFNAME));
                    this.EChartsOption.xAxis.useData.push(item.ALLDISCARDS);
                });
                this.updateFileSystemLine();
            });
        },
        initFileSystemLine(){
            this.ThrowPackage.setOption(this.EChartsOption);
        },
        updateFileSystemLine() {
            this.ThrowPackage.setOption({
                xAxis: {
                    data: this.EChartsOption.xAxis.data
                },
                series: {
                    data: this.EChartsOption.xAxis.useData
                }
            })
        }
    },
    beforeDestroy() {
        bus.$emit('timerNewTodo', {
            name: this.timerName
        });
    },
    watch:{
        
    }
}
</script>

<style scoped>
.ThrowPackage{
    height: 84%;
    margin-bottom: 0 !important;
}
.ThrowPackageLinePage-box{
    height: 100%;
}
.ThrowPackageLinePage{
    height: 100%;
}

</style>